package com.ehotting.edsta.circuitDesign.service.impl;

import com.ehotting.edsta.circuitDesign.domain.EsCircuit;
import com.ehotting.edsta.circuitDesign.domain.EsCircuitCodeDataTemplate;
import com.ehotting.edsta.circuitDesign.enums.SceneTypeEnum;
import com.ehotting.edsta.circuitDesign.enums.StateTypeEnum;
import com.ehotting.edsta.circuitDesign.domain.EsRuleScript;
import com.ehotting.edsta.circuitDesign.mapper.EsRuleScriptMapper;
import com.ehotting.edsta.circuitDesign.service.IEsRuleScriptService;
import com.ehotting.eaf.security.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 脚本信息Service业务层处理
 * 
 * @author edsta
 * @date 2023-06-03
 */
@Service
public class EsRuleScriptServiceImpl implements IEsRuleScriptService
{
    @Autowired
    private EsRuleScriptMapper esRuleScriptMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询脚本信息
     * 
     * @param id 脚本信息主键
     * @return 脚本信息
     */
    @Override
    public EsRuleScript selectEsRuleScriptById(Long id)
    {
        return esRuleScriptMapper.selectEsRuleScriptById(id);
    }

    /**
     * 查询脚本信息列表
     * 
     * @param esRuleScript 脚本信息
     * @return 脚本信息
     */
    @Override
    public List<EsRuleScript> selectEsRuleScriptList(EsRuleScript esRuleScript)
    {
        return esRuleScriptMapper.selectEsRuleScriptList(esRuleScript);
    }

    /**
     * 新增脚本信息
     * 
     * @param esRuleScript 脚本信息
     * @return 结果
     */
    @Override
    public int insertEsRuleScript(EsRuleScript esRuleScript)
    {
        return esRuleScriptMapper.insertEsRuleScript(esRuleScript);
    }

    /**
     * 修改脚本信息
     * 
     * @param esRuleScript 脚本信息
     * @return 结果
     */
    @Override
    public int updateEsRuleScript(EsRuleScript esRuleScript)
    {
        return esRuleScriptMapper.updateEsRuleScript(esRuleScript);
    }

    /**
     * 批量删除脚本信息
     * 
     * @param ids 需要删除的脚本信息主键
     * @return 结果
     */
    @Override
    public int deleteEsRuleScriptByIds(Long[] ids)
    {
        return esRuleScriptMapper.deleteEsRuleScriptByIds(ids);
    }

    /**
     * 删除脚本信息信息
     * 
     * @param id 脚本信息主键
     * @return 结果
     */
    @Override
    public int deleteEsRuleScriptById(Long id)
    {
        return esRuleScriptMapper.deleteEsRuleScriptById(id);
    }

    /**
     * @param sceneId 场景编号
     * @param type  脚本类型
     * 映射关系
     * 1、{@link EsCircuitCodeDataTemplate#getId()} -- {@link SceneTypeEnum#FILTER_PARAM}
     * 2、{@link EsCircuit#getCircuitType()#getId()} -- {@link SceneTypeEnum#CIRCUIT_SELECT}
     * 3、{@link EsCircuit#getId()} --  {@link SceneTypeEnum#ELEMENT_SELECT}
     * @param state
     * {@link com.ehotting.edsta.circuitDesign.enums.StateTypeEnum#YES}
     * @return
     */
    public List<EsRuleScript> findBySceneIdAndTypeAndState(Long sceneId, SceneTypeEnum type, StateTypeEnum state){
        EsRuleScript script = new EsRuleScript();
        script.setSceneId(sceneId);
        script.setSceneType(type);
        script.setState(state);
        return esRuleScriptMapper.selectEsRuleScriptList(script);
    }

}
